package com.xls.box2023.jifen;

import com.lzz.bottomencapsulation.net.RequestCallBack;
import com.xls.box2023.adapter.JiFenMingXiAdapter;
import com.xls.box2023.entity.AccountBalanceEntity;
import com.xls.box2023.entity.JiFenMingXiEntity;
import com.xls.box2023.home.HomeNetWorkUtil;
import com.xls.box2023.mvp.BasePresenterImpl;

import java.util.ArrayList;

import androidx.recyclerview.widget.RecyclerView;

/**
 * MVPPlugin
 */

public class JiFenPresenter extends BasePresenterImpl<JiFenContract.View> implements JiFenContract.Presenter{
    JiFenMingXiAdapter jiFenMingXiAdapter;
    ArrayList<JiFenMingXiEntity> jiFenMingXiDataList=new ArrayList<>();
    @Override
    public RecyclerView.Adapter getJiFenMingXiAdapter() {
        if (jiFenMingXiAdapter==null){
            jiFenMingXiAdapter=new JiFenMingXiAdapter(context,jiFenMingXiDataList);
        }
        return jiFenMingXiAdapter;
    }

    @Override
    public void refresh() {
        getSourceData();
    }

    @Override
    public void getSourceData() {
        super.getSourceData();
        HomeNetWorkUtil.getInstance().getAccountBalance(new RequestCallBack<AccountBalanceEntity>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onStop() {

            }

            @Override
            public void onRequestSuccess(AccountBalanceEntity requestData) {
                if (mView==null||context==null||requestData==null)return;
                mView.showNum(requestData.getFxScoreText());
            }

            @Override
            public void onRequestfail(String errno, String errmsg) {

            }
        });
        JiFenNetWorkUtil.getInstance().getMyAppsAccount(new RequestCallBack<ArrayList<JiFenMingXiEntity>>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onStop() {

            }

            @Override
            public void onRequestSuccess(ArrayList<JiFenMingXiEntity> requestData) {
                if (requestData==null||mView==null||context==null)return;
                jiFenMingXiDataList.clear();
                jiFenMingXiDataList.addAll(requestData);
                jiFenMingXiAdapter.notifyDataSetChanged();
            }

            @Override
            public void onRequestfail(String errno, String errmsg) {

            }
        });
    }
}
